package com.lrkj.lease.controller;

import com.lrkj.lease.domain.LeaseRecord;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.Api;
import java.util.List;

import org.springframework.data.domain.AfterDomainEventPublication;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lrkj.common.annotation.Log;
import com.lrkj.common.core.controller.BaseController;
import com.lrkj.common.core.domain.AjaxResult;
import com.lrkj.common.enums.BusinessType;
import com.lrkj.lease.domain.LeaseContract;
import com.lrkj.lease.service.ILeaseContractService;
import com.lrkj.common.utils.poi.ExcelUtil;
import com.lrkj.common.core.page.TableDataInfo;

/**
 * 租赁合同Controller
 *
 * @author yajun_ren
 * @date 2022-04-26
 */
@RestController
@RequestMapping("/lease/leaseContract")
@Api(tags = "租赁合同")
public class LeaseContractController extends BaseController
{
    @Autowired
    private ILeaseContractService leaseContractService;

    /**
     * 查询租赁合同列表
     */
    @ApiOperation(value = "查询租赁合同列表", notes = "查询租赁合同列表")
    @PreAuthorize("@ss.hasPermi('lease:leaseContract:list')")
    @GetMapping("/list")
    public TableDataInfo list(LeaseContract leaseContract)
    {
        startPage();
        this.changeParameter(leaseContract.getParams());
        List<LeaseContract> list = leaseContractService.selectLeaseContractList(leaseContract);
        return getDataTable(list);
    }

    /**
     * 导出租赁合同列表
     */
	@ApiOperation(value = "导出租赁合同列表", notes = "导出租赁合同列表")
    @PreAuthorize("@ss.hasPermi('lease:leaseContract:export')")
    @Log(title = "租赁合同", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(LeaseContract leaseContract)
    {
        List<LeaseContract> list = leaseContractService.selectLeaseContractList(leaseContract);
        ExcelUtil<LeaseContract> util = new ExcelUtil<LeaseContract>(LeaseContract.class);
        return util.exportExcel(list, "租赁合同数据");
    }

    /**
     * 获取租赁合同详细信息
     */
	@ApiOperation(value = "获取租赁合同详细信息", notes = "获取租赁合同详细信息")
    @PreAuthorize("@ss.hasPermi('lease:leaseContract:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(leaseContractService.selectLeaseContractById(id));
    }

    /**
     * 新增租赁合同
     */
    @ApiOperation(value = "新增租赁合同", notes = "新增租赁合同")
    @PreAuthorize("@ss.hasPermi('lease:leaseContract:add')")
    @Log(title = "租赁合同", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LeaseContract leaseContract)
    {
        return toAjax(leaseContractService.insertLeaseContract(leaseContract));
    }

    /**
     * 修改租赁合同
     */
    @ApiOperation(value = "修改租赁合同", notes = "修改租赁合同")
    @PreAuthorize("@ss.hasPermi('lease:leaseContract:edit')")
    @Log(title = "租赁合同", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LeaseContract leaseContract)
    {
        return toAjax(leaseContractService.updateLeaseContract(leaseContract));
    }

    /**
     * 删除租赁合同
     */
    @ApiOperation(value = "删除租赁合同", notes = "删除租赁合同")
    @PreAuthorize("@ss.hasPermi('lease:leaseContract:remove')")
    @Log(title = "租赁合同", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(leaseContractService.deleteLeaseContractByIds(ids));
    }

    /**
     * 履行合同
     * @param leaseContract
     * @return
     */
    @PreAuthorize("@ss.hasPermi('lease:leaseContract:appleLease')")
    @GetMapping("/appleLease")
    public AjaxResult appleLease(LeaseContract leaseContract){

        return toAjax(leaseContractService.appleLease(leaseContract));
    }


    /**
     * 租赁退租
     * @param leaseContract
     * @return
     */
    @PreAuthorize("@ss.hasPermi('lease:leaseContract:expriyLease')")
    @PutMapping("/expriyLease")
    public AjaxResult expriyLease(@RequestBody LeaseContract leaseContract){
        return toAjax(leaseContractService.expriyLease(leaseContract));
    }


    /**
     * 合同变更
     * @param leaseContract
     * @return
     */
    @PreAuthorize("@ss.hasPermi('lease:leaseContract:beforeRecord')")
    @PutMapping("/beforeRecord")
    public AjaxResult beforeRecord(@RequestBody LeaseContract leaseContract){
        return toAjax(leaseContractService.beforeRecord(leaseContract));
    }
}
